// stores/register.js
import { defineStore } from 'pinia'

export const useRegisterStore = defineStore('register', {
    state: () => ({
        currentOrder: null,
		currentPayment: null, // 新增支付记录存储
        doctorDetail: null,
        scheduleDetail: null,
        department: null,
        selectedSchedule: null // 新增：存储选中的排班信息
    }),

    actions: {
        // 设置订单数据
        setOrderData({ order, payment,doctor, schedule, department }) {
            this.currentOrder = order
			this.currentPayment = payment
            this.doctorDetail = doctor
            this.scheduleDetail = schedule
            this.department = department
        },

        // 设置选中的排班
        setSelectedSchedule(schedule) {
            this.selectedSchedule = schedule
        },

        // 清空数据
        clearOrderData() {
            this.currentOrder = null
            this.doctorDetail = null
            this.scheduleDetail = null
            this.department = null
            this.selectedSchedule = null
        }
    },

    persist: {
        enabled: true,
        strategies: [
            {
                key: 'registerData',
                storage: sessionStorage, // 使用sessionStorage而不是localStorage，因为挂号数据是临时性的
                paths: ['selectedSchedule'] // 只持久化必要的字段
            }
        ]
    }
})